import java.lang.Object;
import java.lang.reflect.Array;
// 泛型类
class MyArray<T>{
    // 使用Object类型的数组

    // 本身T类型在编译时就擦
    // T[] ts = new T[5];
    public Object[] objects = new Object[10];

    public void setValue(int pos,T val){
        objects[pos] = val;
    }

    public T getValue(int pos){
        return (T)objects[pos];
    }
}

class Person implements Comparable<Person>{

    @Override
    public int compareTo(Person o) {
        return 0;
    }
}

class Alg<T extends Comparable<T>>{
    public T findMax(T arr[]){
        T max = arr[0];
        for(int i = 0;i < arr.length;i++){
            if(max.compareTo(arr[i]) < 0){
                max = arr[i];
            }
        }
        return max;
    }
}

class Alg2{
    public<T extends Comparable<T>> T findMax(T arr[]){
        T max = arr[0];
        for(int i = 0;i < arr.length;i++){
            if(max.compareTo(arr[i]) < 0){
                max = arr[i];
            }
        }
        return max;
    }
}

public class test {

    public static void main(String[] args) {
        Alg2 alg2 = new Alg2();
        Integer[] arr2 = {1,2,3};
        int ret1 = alg2.findMax(arr2);
        System.out.println(ret1);

        // 普通引用类型的
        Alg<Integer> b = new Alg<>();

        Integer[] arr = {1,2,3,5,6};
        Integer ret = b.findMax(arr);
        System.out.println(ret);

        // 自定义类型的
        Alg<Person> a = new Alg<>();
    }
    public static void main1(String[] args) {
        MyArray<Integer> myArray1 = new MyArray<>();
        MyArray<String> myArray2 = new MyArray<>();
    }
}
